package socket;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class ClientDemo {

	public static void main(String[] args) {
		try {
			Socket socket=new Socket("192.168.1.115", 8899);
			System.out.println("已连接上服务器");
			Scanner in=new Scanner(System.in);
			String message;
			ObjectOutputStream out=new ObjectOutputStream(socket.getOutputStream());
			ObjectInputStream netin=new ObjectInputStream(socket.getInputStream());
			String serive;
			do{
				message=in.nextLine();
				out.writeObject(message);
				out.flush();
				serive=(String)netin.readObject();
				System.out.println("服务器说："+serive);
			}while(!message.equals("bye"));
			in.close();socket.close();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


//	@Override
//	public void run() {
//		try {
//			ServerSocket server = new ServerSocket(8899);
//			Socket socket=server.accept();
//			ObjectInputStream in=new ObjectInputStream(socket.getInputStream());
//			String m;
//			do{
//				m=(String)in.readObject();
//				System.out.println("服务器说："+m);
//			}while(!m.equals("bye"));
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (ClassNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}   
//	}		
}
